﻿//-----------------------------------------------
// RedditSharp (Reddit#)
//
// Copyright (c) 2011 - 2012
// - Angelo Geels <angelo@angelog.nl>
//-----------------------------------------------

using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace RedditSharp
{
    public class RedditUser
    {
        public string Name;
        public string ID;

        public bool HasMail;
        public bool HasModMail;

        public int TimeCreated;
        public int TimeCreatedUTC;

        public int LinkKarma;
        public int CommentKarma;

        public bool IsGold;
        public bool IsMod;

        /// <summary>
        /// Parses a reddit user based on the Hashtable received.
        /// </summary>
        /// <param name="UserData">The user data in Hashtable form</param>
        /// <returns>The RedditUser</returns>
        public static RedditUser Parse(Hashtable UserData)
        {
            RedditUser ret = new RedditUser();

            ret.Name = (string)UserData["name"];
            ret.ID = (string)UserData["id"];

            ret.HasMail = UserData["has_mail"] != null ? (bool)UserData["has_mail"] : false;
            ret.HasModMail = UserData["has_mod_mail"] != null ? (bool)UserData["has_mod_mail"] : false;

            ret.TimeCreated = (int)(double)UserData["created"];
            ret.TimeCreatedUTC = (int)(double)UserData["created_utc"];

            ret.LinkKarma = (int)(double)UserData["link_karma"];
            ret.CommentKarma = (int)(double)UserData["comment_karma"];

            ret.IsGold = (bool)UserData["is_gold"];
            ret.IsMod = (bool)UserData["is_mod"];

            return ret;
        }

        /// <summary>
        /// Returns the user from a username.
        /// </summary>
        /// <param name="Username">The username</param>
        /// <returns>The RedditUser</returns>
        public static RedditUser Get(string Username)
        {
            return Reddit.GetUser(Username);
        }
    }
}
